package com.hczoop.utils.xml.ben2xml;

import com.thoughtworks.xstream.XStream;

public class XStreamTest {

	public static void main(String[] args) {
		String xml = ben2xml();
		System.out.println(xml);
		System.out.println(xml2ben(xml));
	}
	
	
	public static String ben2xml(){
		XStream xstream = new XStream(); 
		xstream.alias("person", Person.class);  
		xstream.alias("phonenumber", PhoneNumber.class);
		
		Person joe = new Person("Joe", "Walnes");  
		joe.setPhone(new PhoneNumber(123, "1234-456"));  
		  
		String xml = xstream.toXML(joe); 
		return xml;
	}
	
	public static Object xml2ben(String xml){
		XStream xstream = new XStream(); 
		xstream.alias("person", Person.class);  
		xstream.alias("phonenumber", PhoneNumber.class);
		Person person = (Person)xstream.fromXML(xml);  
		return person;
	}

}
